<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
${aier_doctype}
<html <s:property value="aier-html-xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<title>${aier_title}</title>
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/multiselect.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/reset.css" />
<link rel="stylesheet" href="${aier_css_url}social/school/smanage.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/multiselect.js"></script>
<script type="text/javascript" src="${aier_js_url}social/school/sgrade.js"></script>
<script type="text/javascript">
	var global_suffix = "${aier_suffix}", global_url = "${aier_url}", global_uri = "${aier_uri}", global_urijs = "${aier_urijs}", 
	global_sid = "${sid}",global_tid = "${tid}";
</script>
</head>
<!-- 职务管理页面 -->
<body>

	<!-- 顶栏 -->
	<s:action name="userhomecomm_homeHead" namespace="/user"
		executeResult="true"></s:action>

	<!-- 正文 -->
	<div id="hfContent" class="ar-content">
		<div class="content-main">
			<!-- 学校名称栏 -->
			<s:action name="scomm_schoolMTitle" namespace="/school"
				executeResult="true"></s:action>
			<div class="main-content wrap-bg clearfix">
				<!-- 左侧栏 -->
				<s:action name="scomm_schoolMLeft" namespace="/school"
					executeResult="true"></s:action>
				<!-- 右侧内容 -->
				<div class="ae-right">
					<div class="right-main">
						<div class="right-main-top">
							<div class="binfo-title">
								<h3>职务管理</h3>
							</div>
							<div class="right-line"></div>
						</div>
						<div class="right-main-c clearfix">

							<a id="sgAddBtn" href="javascript:;" style="float: right;"
								class="sgadd-btn"> </a>

						</div>

						<div class="right-main-down">
							<div class="down-inre">
								<table id="sGardeInfo"></table>
								<div id="sGardepage"></div>
							</div>
						</div>
					</div>
				</div>
			</div>

		</div>
		<!-- footer copyright -->
		<s:action name="userhomecomm_homeFooter" namespace="/user"
			executeResult="true"></s:action>
		<!-- /footer copyright -->
	</div>


	<!-- 添加作息班级弹出层 -->
	<div id="sgAddDiv" title="添加职务" style="display: none;">
		<div class="info-tab01 sg-add-t">
			<table>
				<tr>
					<th class="gray6 s-profile">职务名称：</th>
					<td style="width: 260px;" colspan="3"><input type="text" class="PY-input" id="gname">
					</td>
				</tr>
				<tr>
					<th class="gray6 s-profile">简述：</th>
					<td colspan="3"><textarea class="s-txtarea" id="gdesinfo"></textarea>
					</td>
				</tr>
				<tr>
					<th class="gray6 s-profile">作息时间：</th>
					<td colspan="3">
						<table class="sg-sch gray6">
							<tr>
								<td><input type="checkbox" title="星期日" id=weekday1><label
									for="weekday1">星期日</label></td>
								<td><input type="checkbox" title="星期一" id="weekday2"
									checked="checked"><label for="weekday2">星期一</label>
								</td>
								<td><input type="checkbox" title="星期二" id="weekday3"
									checked="checked"><label for="weekday3">星期二</label>
								</td>
								<td><input type="checkbox" title="星期三" id="weekday4"
									checked="checked"><label for="weekday4">星期三</label>
								</td>
								<td><input type="checkbox" title="星期四" id="weekday5"
									checked="checked"><label for="weekday5">星期四</label>
								</td>
								<td><input type="checkbox" title="星期五" id="weekday6"
									checked="checked"><label for="weekday6">星期五</label>
								</td>
								<td><input type="checkbox" title="星期六" id="weekday7"><label
									for="weekday7">星期六</label>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<th class="gray6 s-profile"><label for="amStartTime">上午上班时间：</label>
					</th>
					<td><input class="PY-input" type="text" id="amStartTime"
						onfocus="WdatePicker({skin:'twoer',dateFmt:'HH:mm',maxDate:'#F{$dp.$D(\'amEndTime\')}',startDate:'08:00:00',readOnly:true})" />
					</td>
					<th class="gray6 s-profile"><label for="amEndTime">上午下班时间：</label>
					</th>
					<td><input class="PY-input" type="text" id="amEndTime"
						onfocus="WdatePicker({skin:'twoer',dateFmt:'HH:mm',minDate:'#F{$dp.$D(\'amStartTime\')}',startDate:'11:00:00',readOnly:true})" />
					</td>
				</tr>
				<tr>
					<th class="gray6 s-profile"><label for="pmStartTime">下午上班时间：</label>
					</th>
					<td><input class="PY-input" type="text" id="pmStartTime"
						onfocus="WdatePicker({skin:'twoer',dateFmt:'HH:mm',minDate:'#F{$dp.$D(\'amEndTime\')||$dp.$D(\'amStartTime\')}',startDate:'13:00:00',readOnly:true})" />
					</td>
					<th class="gray6 s-profile"><label for="pmEndTime">下午下班时间：</label>
					</th>
					<td><input class="PY-input" type="text" id="pmEndTime"
						onfocus="WdatePicker({skin:'twoer',dateFmt:'HH:mm',minDate:'#F{$dp.$D(\'amEndTime\')||$dp.$D(\'amStartTime\')||$dp.$D(\'pmStartTime\')}',startDate:'17:00:00',readOnly:true})" />
					</td>
				</tr>
			</table>
		</div>
	</div>

	<!-- 修改作息班级弹出层 -->
	<div id="sgUpdateDiv" title="修改职务作息" style="display: none;">
		<div class="info-tab01 sg-add-t">
			<table>
				<tr style="height: 35px;">
					<th class="gray6 s-profile">职务名称：</th>
					<td style="width: 260px;" colspan="3"><input type="text"
						class="PY-input" id="gname_up">
					</td>
				</tr>
				<tr>
					<th class="gray6 s-profile">简述：</th>
					<td colspan="3"><textarea class="s-txtarea" id="gdesinfo_up"></textarea>
					</td>
				</tr>
				<tr>
					<th class="gray6 s-profile"><label for="amStartTime_up">上午上班时间：</label>
					</th>
					<td><input class="PY-input" type="text" id="amStartTime_up"
						onfocus="WdatePicker({skin:'twoer',dateFmt:'HH:mm',maxDate:'#F{$dp.$D(\'amEndTime_up\')}',startDate:'08:00:00'})" />
					</td>
					<th class="gray6 s-profile"><label for="amEndTime_up">上午下班时间：</label>
					</th>
					<td><input class="PY-input" type="text" id="amEndTime_up"
						onfocus="WdatePicker({skin:'twoer',dateFmt:'HH:mm',minDate:'#F{$dp.$D(\'amStartTime_up\')}',startDate:'11:00:00'})" />
					</td>
				</tr>
				<tr>
					<th class="gray6 s-profile"><label for="pmStartTime_up">下午上班时间：</label>
					</th>
					<td><input class="PY-input" type="text" id="pmStartTime_up"
						onfocus="WdatePicker({skin:'twoer',dateFmt:'HH:mm',minDate:'#F{$dp.$D(\'amEndTime_up\')||$dp.$D(\'amStartTime_up\')}',startDate:'13:00:00'})" />
					</td>
					<th class="gray6 s-profile"><label for="pmEndTime_up">下午下班时间：</label>
					</th>
					<td><input class="PY-input" type="text" id="pmEndTime_up"
						onfocus="WdatePicker({skin:'twoer',dateFmt:'HH:mm',minDate:'#F{$dp.$D(\'amEndTime_up\')||$dp.$D(\'amStartTime_up\')||$dp.$D(\'pmStartTime_up\')}',startDate:'17:00:00'})" />
					</td>
				</tr>
				<tr>
					<td colspan="4" align="right">
						<table id="sgWeeks" border="1" bordercolor="#DDDDDD">
							<tr align="center">
								<td width="50px"></td>
								<td class="data2" onclick="pdSel('2')"><span>周一</span><input
									id="cb2" type="checkbox" onclick="pdSel('2')">
								</td>
								<td class="data3" onclick="pdSel('3')"><span>周二</span><input
									id="cb3" type="checkbox" onclick="pdSel('3')">
								</td>
								<td class="data4" onclick="pdSel('4')"><span>周三</span><input
									id="cb4" type="checkbox" onclick="pdSel('4')">
								</td>
								<td class="data5" onclick="pdSel('5')"><span>周四</span><input
									id="cb5" type="checkbox" onclick="pdSel('5')">
								</td>
								<td class="data6" onclick="pdSel('6')"><span>周五</span><input
									id="cb6" type="checkbox" onclick="pdSel('6')">
								</td>
								<td class="data7" onclick="pdSel('7')"><span>周六</span><input
									id="cb7" type="checkbox" onclick="pdSel('7')">
								</td>
								<td class="data1" onclick="pdSel('1')"><span>周日</span><input
									id="cb1" type="checkbox" onclick="pdSel('1')">
								</td>
							</tr>
							<tr align="center">
								<td><span>上午</span>
								</td>
								<td class="data2" onclick="pdSel('2')"><span id="sadata2"></span>--<span
									id="eadata2"></span>
								</td>
								<td class="data3" onclick="pdSel('3')"><span id="sadata3"></span>--<span
									id="eadata3"></span>
								</td>
								<td class="data4" onclick="pdSel('4')"><span id="sadata4"></span>--<span
									id="eadata4"></span>
								</td>
								<td class="data5" onclick="pdSel('5')"><span id="sadata5"></span>--<span
									id="eadata5"></span>
								</td>
								<td class="data6" onclick="pdSel('6')"><span id="sadata6"></span>--<span
									id="eadata6"></span>
								</td>
								<td class="data7" onclick="pdSel('7')"><span id="sadata7"></span>--<span
									id="eadata7"></span>
								</td>
								<td class="data1" onclick="pdSel('1')"><span id="sadata1"></span>--<span
									id="eadata1"></span>
								</td>
							</tr>
							<tr align="center">
								<td><span>下午</span>
								</td>
								<td class="data2" onclick="pdSel('2')"><span id="spdata2"></span>--<span
									id="epdata2"></span>
								</td>
								<td class="data3" onclick="pdSel('3')"><span id="spdata3"></span>--<span
									id="epdata3"></span>
								</td>
								<td class="data4" onclick="pdSel('4')"><span id="spdata4"></span>--<span
									id="epdata4"></span>
								</td>
								<td class="data5" onclick="pdSel('5')"><span id="spdata5"></span>--<span
									id="epdata5"></span>
								</td>
								<td class="data6" onclick="pdSel('6')"><span id="spdata6"></span>--<span
									id="epdata6"></span>
								</td>
								<td class="data7" onclick="pdSel('7')"><span id="spdata7"></span>--<span
									id="epdata7"></span>
								</td>
								<td class="data1" onclick="pdSel('1')"><span id="spdata1"></span>--<span
									id="epdata1"></span>
								</td>
							</tr>
						</table>
			</table>
		</div>

	</div>

	<!-- 删除弹出层 -->
	<div id="compPrompt" title="提示" style="display: none;">
		<span>确认删除吗？</span>
	</div>
</body>
<script type="text/javascript">
	//设置班级为下拉复选框
	$("#teacherTypes").multiselect({
		noneSelectedText : "请选择",
		selectedText : "已选中#个班级",
		selectedList : 2
	});
 
	$(function() {
		var sadate1 = $('#amStartTime'),
		eadate1 = $('#amEndTime'),
		spdate1 = $('#pmStartTime'),
		epdate1 = $('#pmEndTime'),
		gname1 = $('#gname'),
		gdesinfo1 = $('#gdesinfo'),
		allFields = $( [] ).add(sadate1).add(eadate1).add(spdate1).add(epdate1).add(gname1).add(gdesinfo1);
		
		//添加班级弹出层
		$("#sgAddDiv").dialog({
			//背景变暗
			modal: true,
			autoOpen : false,
			show : "fade",
	        hide : "fade",
			width : "670",
			height : "410",
			buttons: {
				"确定": function() {
					allFields.removeClass( "ui-state-error" );
					var sadate = $('#amStartTime').val(),
					eadate = $('#amEndTime').val(),
					spdate = $('#pmStartTime').val(),
					epdate = $('#pmEndTime').val(),
					gname = $('#gname').val(),
					gdesinfo = $('#gdesinfo').val();
					var daynum="";
					if(gname.trim()==""){
						$().message("请填写职务名称！");
						return
					}
					if((sadate.trim()!=""&&epdate.trim()=="")||(sadate.trim()==""&&epdate.trim()!="")){
						$().message("请填写上午上班时间以及下午下班时间！");
						return
					}
					if((eadate.trim()!=""&&spdate.trim()=="")||(eadate.trim()==""&&spdate.trim()!="")){
						$().message("上午下班时间和下午上班时间不能只填写一个！");
						return
					}
					
					for(var i=1;i<8;i++){
						if ($("#weekday"+i).attr("checked") == "checked") {
							if(8==i){
								daynum += i;
							}else{
								daynum += i+",";
							}
						}
					}
			
					var funadd = function(data){
						if (data.s == 1) {
							$().message("添加职务成功!");
							$("#sGardeInfo").trigger("reloadGrid");
							$("#sgAddDiv").dialog("close");
						} else {
							$().message(data.error_info);
						}
					};
					exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoolgrade_addSchoolGrade${aier_suffix}"), funadd, 
					{"sid" :global_sid,
					 "gname" : gname,
					 "gdesinfo" : gdesinfo,
					 "daynum" : daynum.trim(),
					 "txt_sadate":sadate,
					 "txt_eadate":eadate,
					 "txt_spdate":spdate,
					 "txt_epdate":epdate});
				},"取消": function() {
					$( this ).dialog( "close" );
				}
			},
		close: function() {
			allFields.val( "" ).removeClass( "ui-state-error" );
			for(var i=2;i<7;i++){
				$("#weekday"+i).attr("checked",true);
			}
			$("#weekday1").attr("checked",false);
			$("#weekday7").attr("checked",false);
		}
		});
		$("#sgAddBtn").click(function() {
			$("#sgAddDiv").dialog("open");
			return false;
		});
	});
	
	//修改职务
	function upTel(id){
		$("#sgUpdateDiv").dialog({
			//背景变暗
			modal : true,
			autoOpen : false,
			show : "fade",
			hide : "fade",
			width : "670",
			height : "500",
			buttons : {
			"确定" : updateAtt,
			"取消" : function() {
				$(this).dialog("close");
			}
			}
		});
		$("#sgUpdateDiv").dialog("open");
		OptionManage(id);
	}
	
	function pdSel(i){
		 $("#amStartTime_up").val($("#sadata"+i).html());
	     $("#amEndTime_up").val($("#eadata"+i).html());
	     $("#pmStartTime_up").val($("#spdata"+i).html());
	     $("#pmEndTime_up").val($("#epdata"+i).html());
         if($("#cb"+i).attr("checked") == "checked"){
         	$("#cb"+i).attr("checked", false);
         	$(".data"+i).removeClass("odd");
         }else{
         	$("#cb"+i).attr("checked", true);
         	$(".data"+i).addClass("odd");
         }
	         
	}
	
var gid;	
//进入作息修改
function OptionManage(id){
	$("#amStartTime_up").val("");
	$("#amEndTime_up").val("");
	$("#pmStartTime_up").val("");
	$("#pmEndTime_up").val("");
	for(var i=1;i<8;i++){
		$("#cb"+i).attr("checked", false);
		$(".data"+i).removeClass("odd");
	}
	var funshow = function(data){
		$('#gname_up').val(data.schoolGrade.name);//职务名
		$('#gdesinfo_up').val(data.schoolGrade.desinfo);
		gid=data.schoolGrade.gid;
		//initTypeValue();
		for(var i=1;i<8;i++){
				$("#sadata"+i).html("");
				$("#eadata"+i).html("");
				$("#spdata"+i).html("");
				$("#epdata"+i).html("");
			}
		for ( var i = 0; i < data.schoolGrade.sgaList.length; i++) {
			var sga = data.schoolGrade.sgaList[i];
			var sadate = (sga.sadate==null?"":sga.sadate.split("T")[1].substring(0,5));
			var eadate = (sga.eadate==null?"":sga.eadate.split("T")[1].substring(0,5));
			var spdate = (sga.spdate==null?"":sga.spdate.split("T")[1].substring(0,5));
			var epdate = (sga.epdate==null?"":sga.epdate.split("T")[1].substring(0,5));
			switch (sga.type) {
				case 1:
					$("#sadata1").html(sadate);
					$("#eadata1").html(eadate);
					$("#spdata1").html(spdate);
					$("#epdata1").html(epdate);
					break;
				case 2:
					
					$("#sadata2").html(sadate);
					$("#eadata2").html(eadate);
					$("#spdata2").html(spdate);
					$("#epdata2").html(epdate);
					break;
				case 3:
					$("#sadata3").html(sadate);
					$("#eadata3").html(eadate);
					$("#spdata3").html(spdate);
					$("#epdata3").html(epdate);
					break;
				case 4:
					$("#sadata4").html(sadate);
					$("#eadata4").html(eadate);
					$("#spdata4").html(spdate);
					$("#epdata4").html(epdate);
					break;
				case 5:
					$("#sadata5").html(sadate);
					$("#eadata5").html(eadate);
					$("#spdata5").html(spdate);
					$("#epdata5").html(epdate);
					break;
				case 6:
					$("#sadata6").html(sadate);
					$("#eadata6").html(eadate);
					$("#spdata6").html(spdate);
					$("#epdata6").html(epdate);
					break;
				case 7:
					$("#sadata7").html(sadate);
					$("#eadata7").html(eadate);
					$("#spdata7").html(spdate);
					$("#epdata7").html(epdate);
					break;
				default:
					break;
			}	
		};
	};
	exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoolgrade_showSchoolGrade${aier_suffix}"), funshow, {"gid" :jQuery("#sGardeInfo").jqGrid('getRowData', id).gid});
	
}


//同步作息显示列表(删除或修改操作过后)
function synshow(){
	$("#sGardeInfo").trigger("reloadGrid");
	var sadate = $('#amStartTime_up').val();
	var eadate = $('#amEndTime_up').val();
	var spdate = $('#pmStartTime_up').val();
	var epdate = $('#pmEndTime_up').val();

	if(sadate.trim()==""&&eadate.trim()==""&&spdate.trim()==""&&epdate.trim()==""){	
		var datas = daynum.split(",");	
		for(var i=0;i<datas.length;i++){
			$("#sadata"+datas[i]).html("");
       		$("#eadata"+datas[i]).html("");
       		$("#spdata"+datas[i]).html("");
         	$("#epdata"+datas[i]).html("");
		}
	}else{
		var datas = daynum.split(",");	
		for(var i=0;i<datas.length;i++){
			$("#sadata"+datas[i]).html(sadate);
       		$("#eadata"+datas[i]).html(eadate);
       		$("#spdata"+datas[i]).html(spdate);
         	$("#epdata"+datas[i]).html(epdate);
		}	
	}
}
var daynum="";
//修改周期作息时间
function updateAtt(){
	var sadate = $('#amStartTime_up').val();
	var eadate = $('#amEndTime_up').val();
	var spdate = $('#pmStartTime_up').val();
	var epdate = $('#pmEndTime_up').val();
	var gname_up = $('#gname_up').val();
	var gdesinfo = $('#gdesinfo').val();
	if(gname_up.trim()==""){
		$().message("请输入职务名！");
		return
	}
	if((sadate.trim()!=""&&epdate.trim()=="")||(sadate.trim()==""&&epdate.trim()!="")){
		$().message("请填写上午上班时间以及下午下班时间！");
		return
	}
	if((eadate.trim()!=""&&spdate.trim()=="")||(eadate.trim()==""&&spdate.trim()!="")){
		$().message("上午下班时间和下午上班时间不能只填写一个！");
		return
	}
	if(eadate.trim()!=""&&spdate.trim()!=""&&sadate.trim()==""&&epdate.trim()==""){
		$().message("请填写上午上班时间以及下午下班时间！");
		return
	}
	
	for(var i=1;i<8;i++){
		if ($("#cb"+i).attr("checked") == "checked") {
			if(8==i){
				daynum += i;
			}else{
				daynum += i+",";
			}
		}
	}

	if(isnull(daynum)){
		$().message("请选择一个周期进行修改！");
		return
	}

	//修改
	var funup = function(data){
		if(data.s==1){
			$().message("修改周期成功");
			synshow();
			daynum="";
		}else{
			$().message("修改周期失败:"+data.error_info);
		}	
	};
	exeAjax(ajaxUrl("${aier_url}${aier_urijs}schoolgrade_updateSchoolGrade${aier_suffix}"), funup, 
		{
		"sid" : global_sid,
		"gid" : gid,
		"gname" : gname_up,
		"gdesinfo" : gdesinfo,
		"daynum" : daynum.trim(),
		"txt_sadate":sadate,
		"txt_eadate":eadate,
		"txt_spdate":spdate,
		"txt_epdate":epdate});
}	
</script>
</html>